#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothSocket>
#include <QHash>
#include <QMainWindow>
#include <QSet>
#include <QSettings>

class QLabel;
class QMediaPlayer;
class QTextToSpeech;
class QEvent;
class QPaintEvent;
class QByteArray;
class QBlueToothDeviceInfo;
class Bluetooth;
class SocketBuf;
class QTableWidgetItem;

QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE

extern const QHash<QString, QString> nameToQm;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

    bool setTheme(const QString& qss);
    void addTransactionRecord(const QString& dateTime, const QString& name, const QString& price, const QString& weight, const QString& total);

protected:
    virtual bool eventFilter(QObject* watched, QEvent* event) override;
    virtual void paintEvent(QPaintEvent* event) override;
    virtual bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
    virtual void closeEvent(QCloseEvent* event) override;

private slots:
    void saveSettings();
    void switchLanguage(const QString& arg1);
    void enableEdit();
    void disAbleEdit();
    void clearContents();
    void addBlueToothDeviceToCombobox(const QBluetoothDeviceInfo& info);
    void onSocketError(QBluetoothSocket::SocketError error);
    void onDiscoverError(QBluetoothDeviceDiscoveryAgent::Error error);
    void blueToothConnected();
    void readSocketData();
    void processBlueToothRecive();
    void remove_goods();
    void add_freq();
    void remove_freq();
    void freqPb_toggeled();
    void eidtItem(QTableWidgetItem* item);
    void setPrice(QTableWidgetItem* item);

    void on_connect_pb_clicked();
    void on_Switch_pb_clicked();
    void on_Pre_pb_clicked();
    void on_Nex_pb_clicked();
    void on_Enter_pb_clicked();
    void on_add_pb_clicked();
    void on_search_returnPressed();
    void on_search_textChanged(const QString& arg1);
    void on_pcVolume_valueChanged(int value);
    void on_pcSpeed_valueChanged(int value);
    void on_mcuVolume_sliderReleased();
    void on_mcuSpeed_sliderReleased();
    void on_selectTheme_clicked();
    void on_blue_clicked();
    void on_red_clicked();
    void on_green_clicked();
    void on_refresh_clicked();
    void on_searchTransaction_textChanged(const QString& arg1);
    void on_searchTransaction_returnPressed();
    void on_powerSaving_clicked();

private:
    Ui::MainWindow* ui;
    QLabel* statusBarMessage; // 状态栏提示信息
    QMediaPlayer* player; // 播放音乐
    QTextToSpeech* tts; // 语音播报
    Bluetooth* bluetooth; // 蓝牙类
    SocketBuf* socketBuf; // 通信队列类
    QSettings settings;
    QSettings transactionRecordConfig;
    QString currentTheme;
    QHash<int, int> valueToId;
};
#endif // MAINWINDOW_H
